package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.ContactBasic;
import com.group.project.hrms.mapper.ContactBasicMapper;
import com.group.project.hrms.service.IContactBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class ContactBasicService implements IContactBasicService {

    @Autowired
    private ContactBasicMapper contactBasicMapper;

    @Override
    public int insertContactBasic(ContactBasic contactBasic) {
        return contactBasicMapper.insert(contactBasic);
    }

    @Override
    public int deleteContactBasic(ContactBasic contactBasic) {
        return contactBasicMapper.deleteByPrimaryKey(contactBasic);
    }

    @Override
    public int updateContactBasic(ContactBasic contactBasic) {
        return contactBasicMapper.updateByPrimaryKey(contactBasic);
    }

    @Override
    public ContactBasic selectOneContactBasic(ContactBasic contactBasic) {
        return contactBasicMapper.selectByPrimaryKey(contactBasic);
    }

    @Override
    public ContactBasic selectContactBasicByUnID(String unid) {
        Example example = new Example(ContactBasic.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("dingUnionid" , unid);
        return contactBasicMapper.selectOneByExample(example);
    }

    @Override
    public ContactBasic selectContactBasicByContactID(String cid) {
        Example example = new Example(ContactBasic.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("contactId" , cid);
        return contactBasicMapper.selectOneByExample(example);
    }

    @Override
    public List<ContactBasic> selectAllContactBasicByStaffStatus(int status) {
        Example example = new Example(ContactBasic.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orEqualTo("staffStatus" , status);
        return contactBasicMapper.selectByExample(example);
    }

    @Override
    public List<ContactBasic> selectAllContactBasic() {
        return contactBasicMapper.selectAll();
    }
}
